/**
 *  Date: 2020/08/20 Time: 23:07
 */

import {Action} from "../../../configuration/ActionCreator"
import {FetchStatus, RequestAction, RequestMethod} from "../../../configuration/RequestConfiguration";
import {AppRequestPath} from "../../../configuration/AppConfig";
import {API_PROCEDURE2,API_PROCEDURE} from "../../../constant/API";
import global from "../../../configuration/global";

//------------------------------删除值班人员----------------------------------
export const RetrieveRoomChangeReport = 'RetrieveRoomChangeReport';
export const retrieveRoomChangeReport = (str) => {
    let action = Action(RetrieveRoomChangeReport);
    return dispatch => dispatch(request_retrieveRoomChangeReport(action, str))
};

export const request_retrieveRoomChangeReport = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'ALINCustomSelect',
            'jn': str,
            'jnJson2': [{"page":1,"sord":"asc","rows":-1,"sidx":"opdate,time,oldroom"}],
            'jnJson3': 'list'
        },
        action
    )
};

export const onRetrieveRoomChangeReport = (state = {}, action) => {
    switch (action.type) {
        case RetrieveRoomChangeReport: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


//------------------------------获取房间历史----------------------------------
export const RetrieveRoomHistory = 'RetrieveRoomHistory';
export const retrieveRoomHistory = (str) => {
    let action = Action(RetrieveRoomHistory);
    return dispatch => dispatch(request_retrieveRoomHistory(action, str))
};

export const request_retrieveRoomHistory = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'ListRetrieveRoomHistory',
            'jn': str,
            'jnJson2': '{}',
            'jnJson3': 'list'
        },
        action
    )
};

export const onRetrieveRoomHistory = (state = {}, action) => {
    switch (action.type) {
        case RetrieveRoomHistory: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

